package servlet;

import java.io.*;
import java.net.*;

import javax.servlet.*;
import javax.servlet.http.*;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

import mgr.OrdenPedidoManager;

public class AnularPedidoAction extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
        procesar(req, resp);
    }
    
    public void doPost(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
        procesar(req, resp);
    }
    
    private void procesar(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String[] itemsID = req.getParameterValues("itemID");
        try{
            for(int i = 0; i < itemsID.length; i ++){
                //System.out.println(itemsID[i]);
                OrdenPedidoManager orden = new OrdenPedidoManager();
                orden.anularOrdenPedido(itemsID[i]);
            }
            getServletContext().getRequestDispatcher("/Listado_Pedidos.jsp?mensajeAnulado=YES").forward(req, resp);
        }
        catch (Exception e) {
            PrintWriter out = resp.getWriter();
            out.println("<HTML>");
            out.println("<HEAD>");
            out.println("</HEAD>");
            out.println("<BODY>");

            String msg = (String) e.getMessage();
            out.println("<P>" + msg + "</P>");

            out.println("</BODY>");
            out.println("</HTML>");
	}
    }
}